package com.platform.controller;

import com.platform.entity.MerchantInviteEntity;
import com.platform.service.MerchantInviteService;
import com.platform.utils.PageUtils;
import com.platform.utils.Query;
import com.platform.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 商城配置:官网申请加盟
 *
 * @author liweihai
 * @email liweihai12345@sina.com
 * @date 2019-04-02 18:12:09
 */
@RestController
@RequestMapping("merchantinvite")
public class MerchantInviteController {
    @Autowired
    private MerchantInviteService merchantInviteService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("merchantinvite:list")
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<MerchantInviteEntity> merchantInviteList = merchantInviteService.queryList(query);
        int total = merchantInviteService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(merchantInviteList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("merchantinvite:info")
    public R info(@PathVariable("id") Long id) {
        MerchantInviteEntity merchantInvite = merchantInviteService.queryObject(id);

        return R.ok().put("merchantInvite", merchantInvite);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("merchantinvite:save")
    public R save(@RequestBody MerchantInviteEntity merchantInvite) {
        merchantInviteService.save(merchantInvite);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("merchantinvite:update")
    public R update(@RequestBody MerchantInviteEntity merchantInvite) {
        merchantInviteService.update(merchantInvite);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("merchantinvite:delete")
    public R delete(@RequestBody Long[] ids) {
        merchantInviteService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<MerchantInviteEntity> list = merchantInviteService.queryList(params);

        return R.ok().put("list", list);
    }
}
